import Config from "@/settings";

const TokenKey = Config.TokenKey;
const AccountKey = Config.AccountKey;
const UserIdKey = Config.UserIdKey;

export function getToken() {
  return localStorage.getItem(TokenKey);
}

// transfer one params to new token
export function setToken(token, rememberMe) {
  if (rememberMe) {
    return localStorage.setItem(TokenKey, token, {
      expires: Config.tokenCookieExpires,
    });
  } else return localStorage.setItem(TokenKey, token);
}

export function removeToken() {
  return localStorage.removeItem(TokenKey);
}

// user account
export function getAccount() {
  return JSON.parse(localStorage.getItem(AccountKey));
}

export function setAccount(accountInfo) {
  return localStorage.setItem(AccountKey, JSON.stringify(accountInfo));
}

export function removeAccount() {
  return localStorage.removeItem(AccountKey);
}

// user uuid
export function getUserId() {
  return localStorage.getItem(UserIdKey);
}

export function setUserId(id) {
  return localStorage.setItem(UserIdKey, id);
}

export function removeUserId() {
  return localStorage.removeItem(UserIdKey);
}
